<template>
  <ElementDialog ref="dialog" embed :visible="visible" title="添加研究阶段" v-on="$listeners">
    <FormHolder ref="form" :disabled="disabled" label-width="130px" :model="entity">
      <FormInput v-model="entity.matter" prop="matter" label="事项" required/>
      <FormDatePicker v-model="entity.time" prop="time" label="时间" required/>
      <FormTextarea v-model="entity.remark" max-length="1500" prop="remark" label="备注" rows="10"/>
    </FormHolder>
    <template #footer>
      <ElButton v-if="!disabled" size="mini" type="primary" @click="save">确定</ElButton>
      <ElButton size="mini" @click="close">取消</ElButton>
    </template>
  </ElementDialog>
</template>

<script>
  import { save } from './api'
  import { cloneDeep } from '@web-utils/integrations/lodash'

  export default {
    name: 'StageEditDialog',
    props: {
      visible: Boolean,
      saveForm: Boolean,
      disabled: Boolean,
      value: Object
    },
    data() {
      return {
        entity: {
          id: null,
          unid: null,
          createTime: null,
          createBy: null,
          createId: null,
          deptId: null,
          deptFullName: null,
          updateTime: null,
          updateId: null,
          updateBy: null,
          tenantId: null,
          delFlag: null,
          time: null,
          matter: null,
          remark: null,
          projectId: null,
          projectName: null,
        }
      }
    },
    watch: {
      value: {
        immediate: true,
        handler(newVal) {
          if (newVal) {
            this.entity = cloneDeep(newVal)
          } else {
            this.entity = this.$options.data.call(this).entity
          }
        }
      }
    },
    methods: {
      async save() {
        await this.$refs.form.validate()
        if (this.saveForm) {
          await save(this.entity)
        }
        this.$emit('confirm',this.entity)
        this.close()
      },
      close(){
        this.$refs.dialog.hide()
      }
    },
  }
</script>
